package yingyong;

import gongju.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/delete")
public class Delete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("text/html;character=utf8");
        String id = req.getParameter("id");
        String sql = "delete from emp where EmpID = ?;";
        try {
            int i = DBUtil.update(sql,id);
            resp.setCharacterEncoding("utf8");
            if (i>0){
                resp.getWriter().write("<script>alert('删除成功');location.href='/select';</script>");
            }else {
                resp.getWriter().write("<script>alert('删除失败');location.href='/select';</script>");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }
}
